import { ItemData } from "../../../../resource/info/ItemData";
import { VipDescConfig } from "../../../../resource/VipDescConfig";
import { ItemsUtil } from "../../../shortcuts/item/ItemsUtil";
import { HTMLUtil } from "../../../../../../com/gengine/utils/HTMLUtil";
import { ParamsConst } from "../../../../../common/global/ParamsConst";
import { ProxyType } from "../../../../../common/global/ProxyType";
import { TItem } from "../../../../../../Message/Db/Tables/TItem";
import { CareerUtil } from "../../util/CareerUtil";
import { Cache } from "../../../../cache/Cache";
import { CareerConfig } from "../../../../resource/CareerConfig";
import { ECategory } from "../../../../../../Message/Public/ECategory";
import { ItemConfig } from "../../../../resource/ItemConfig";
import { SecondCareerConfig } from "../../../../resource/SecondCareerConfig";
import { ECareerSecondTran } from "../../../../../../Message/Public/ECareerSecondTran";
import { ChangeHeadIconConfig } from "../../../../resource/ChangeHeadIconConfig";
//class ToolTipUtil
    
    export  class ToolTipUtil
    {
        

        public static getItemDescText(arg1: ItemData): string
        {
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc6=null;
            if (arg1 == null || arg1.itemInfo == null) 
            {
                return "";
            }
            var loc1=arg1.itemInfo.item;
            var loc2="";
            if (loc1) 
            {
                loc3 = "";
                if ((loc4 = int(loc1.descStr)) > 0) 
                {
                    loc3 = VipDescConfig.instance.getVipFullDescByType(loc4);
                }
                else if (ItemsUtil.isIllustrate(arg1)) 
                {
                    if ((loc5 = loc1.descStr.split("$")) && loc5[0]) 
                    {
                        loc3 = loc5[0];
                    }
                }
                else 
                {
                    loc3 = loc1.descStr;
                }
                if (!(loc3 == "") && !(loc3 == "0")) 
                {
                    loc3 = ItemsUtil.getGiftBagDes(loc1.code, loc3);
                    loc2 = "<textFormat leading=\'5\'>" + HTMLUtil.addColor(loc3, "#ffffff") + "</textFormat>";
                }
            }
            if (ParamsConst.instance.proxyType == ProxyType.TW && !(ParamsConst.instance.gameName == null)) 
            {
                if (loc2.indexOf(ParamsConst.instance.gameName) >= 0) 
                {
                    loc6 = new RegExp(ParamsConst.instance.gameName, "g");
                    loc2 = loc2.replace(loc6, "");
                }
            }
            return loc2;
        }

        public static getNeedCareerName(arg1: TItem): string
        {
            var loc2=null;
            var loc1=ToolTipUtil.getCareerName(arg1);
            if (loc1 != "") 
            {
                loc2 = "#ff87dc";
                if (arg1) 
                {
                    if (!CareerUtil.isCareerSuit(arg1.career, Cache.instance.role.roleInfo.career)) 
                    {
                        loc2 = "#ff0000";
                    }
                }
                loc1 = HTMLUtil.addColor(loc1, loc2);
            }
            return loc1;
        }

        public static getCareerName(arg1: TItem): string
        {
            var loc1="";
            var loc2=null;
            if (arg1) 
            {
                if (arg1.career != 0) 
                {
                    loc2 = CareerConfig.instance.getInfoByCode(arg1.career);
                    if (loc2) 
                    {
                        loc1 = loc2.name;
                    }
                }
            }
            return loc1;
        }

        public static isOwnIllustrateByItemdata(arg1: ItemData): Boolean
        {
            var loc4=0;
            var loc5=null;
            var loc1=false;
            var loc2=[];
            loc2 = loc2.concat(Cache.instance.pack.backPackCache.getTypeItems(ECategory._ECategoryIllustrate));
            loc2 = loc2.concat(Cache.instance.pack.wareHousePackCache.getTypeItems(ECategory._ECategoryIllustrate));
            var loc3=loc2.length;
            loc4 = 0;
            while (loc4 < loc3) 
            {
                loc5 = loc2[loc4];
                if (arg1 && loc5 && arg1.effectEx == loc5.effectEx && arg1.color == loc5.color && !ToolTipUtil.isActiveIllustrateByItemdata(loc5)) 
                {
                    loc1 = true;
                    break;
                }
                ++loc4;
            }
            return loc1;
        }

        public static isActiveIllustrateByItemdata(arg1: ItemData): Boolean
        {
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc1=false;
            var loc2=Cache.instance.illustrate.illustrateMap;
            if (loc2) 
            {
                var loc7=0;
                var loc8=loc2;
                for(loc4 of loc8) 
                {
                    if (loc4) 
                    {
                        loc5 = loc4.pieces;
                        var loc9=0;
                        var loc10=loc5;
                        for(loc6 of loc10) 
                        {
                            if (loc6 == 0) 
                            {
                                continue;
                            }
                            loc3 = new ItemData(loc6);
                            if (!(arg1 && loc3 && arg1.effectEx == loc3.effectEx && arg1.color <= loc3.color)) 
                            {
                                continue;
                            }
                            loc1 = true;
                            break;
                        }
                    }
                    if (!loc1) 
                    {
                        continue;
                    }
                    break;
                }
            }
            return loc1;
        }

        public static isOwnRuneByItemData(arg1: ItemData): Boolean
        {
            var loc7=null;
            var loc8=null;
            var loc9=false;
            var loc10=null;
            var loc12=null;
            var loc15=null;
            var loc16=0;
            var loc1=false;
            var loc2=[];
            loc2 = loc2.concat(Cache.instance.pack.backPackCache.getTypeItems(ECategory._ECategoryRune));
            loc2 = loc2.concat(Cache.instance.pack.wareHousePackCache.getTypeItems(ECategory._ECategoryRune));
            loc2 = loc2.concat(Cache.instance.pack.runePackCache.getAllItems());
            var loc3=loc2.length;
            var loc4=0;
            var loc5=0;
            var loc6=0;
            var loc11=false;
            var loc13=ItemConfig.instance.getPropsByCategory(ECategory._ECategoryRune);
            var loc14=[];
            loc4 = 0;
            while (loc4 < loc3) 
            {
                if ((loc7 = loc2[loc4]) != null) 
                {
                    if (arg1 && arg1.name == loc7.name) 
                    {
                        loc1 = true;
                        break;
                    }
                    loc14.splice(0);
                    loc16 = loc13.length;
                    loc5 = 0;
                    while (loc5 < loc16) 
                    {
                        loc15 = loc13[loc5];
                        if (loc7 && loc15 && loc7.name == loc15.item.name) 
                        {
                            loc14.push(loc15.item.code);
                        }
                        ++loc5;
                    }
                    if (loc9 = ItemsUtil.isHolyRune(loc7)) 
                    {
                        loc10 = loc7.runeSwallowCodes;
                        loc16 = loc13.length;
                        loc5 = 0;
                        while (loc5 < loc10.length) 
                        {
                            loc8 = new ItemData(loc10[loc5]);
                            loc6 = 0;
                            while (loc6 < loc16) 
                            {
                                loc15 = loc13[loc6];
                                if (loc8 && loc15 && loc8.name == loc15.item.name) 
                                {
                                    loc14.push(loc15.item.code);
                                }
                                ++loc6;
                            }
                            ++loc5;
                        }
                    }
                    loc16 = loc14.length;
                    loc6 = 0;
                    while (loc6 < loc16) 
                    {
                        if ((loc12 = SecondCareerConfig.instance.getRuneInfo(loc14[loc6], ECareerSecondTran._ECareerSecondRune)) && arg1 && (loc12.codeF == arg1.itemCode || loc12.codeT == arg1.itemCode || loc12.codeW == arg1.itemCode || loc12.codeY == arg1.itemCode)) 
                        {
                            loc11 = true;
                        }
                        else 
                        {
                            loc11 = false;
                        }
                        if (loc11) 
                        {
                            loc1 = true;
                            break;
                        }
                        ++loc6;
                    }
                    if (loc1) 
                    {
                        break;
                    }
                }
                ++loc4;
            }
            return loc1;
        }

        public static isOwnAvatarByItemdata(arg1: ItemData): Boolean
        {
            var loc4=0;
            var loc5=null;
            var loc7=null;
            var loc9=0;
            var loc10=null;
            var loc1=false;
            var loc2=[];
            loc2 = loc2.concat(Cache.instance.pack.backPackCache.getItemsByJudge(ItemsUtil.isAvatar));
            loc2 = loc2.concat(Cache.instance.pack.wareHousePackCache.getItemsByJudge(ItemsUtil.isAvatar));
            var loc3=loc2.length;
            var loc6=ChangeHeadIconConfig.instance.getHeadIconId(arg1.codeUnbind);
            loc4 = 0;
            while (loc4 < loc3) 
            {
                loc5 = loc2[loc4];
                if (arg1 && loc5 && loc5.codeUnbind == arg1.codeUnbind) 
                {
                    loc1 = true;
                    break;
                }
                loc7 = ChangeHeadIconConfig.instance.getHeadIconId(loc5.codeUnbind);
                if (loc6 && loc7 && loc6.avatarid == loc7.avatarid || loc6.oppositeId == loc7.avatarid) 
                {
                    loc1 = true;
                    break;
                }
                ++loc4;
            }
            var loc8=Cache.instance.role.headIconArr;
            var loc11=0;
            while (loc11 < loc8.length) 
            {
                loc9 = loc8[loc11];
                if (arg1) 
                {
                    if ((loc10 = ChangeHeadIconConfig.instance.getHeadIconId(arg1.codeUnbind)) && loc10.avatarid == loc9 || loc10.oppositeId == loc9) 
                    {
                        loc1 = true;
                        break;
                    }
                }
                ++loc11;
            }
            return loc1;
        }
    }
